package game.Screens;

import game.Game;
import game.GameHud;
import game.LevelManager;
import game.Actors.Actor;
import game.Config.Config;
import game.Config.Storage;
import game.Config.Config.GameInput;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;

/**
 * The screen where the player can upgrade a tower.
 * @author Sebastian Isheden and Victor Beer
 *
 */
public class TowerUpgradeScreen extends Screen{
	boolean fullyUpgraded;
	/**
	 * Initalizes the screen.
	 */
	@Override
	public void begin() {
		fullyUpgraded = Storage.getTower().getUpgradeInfo() == null;
	}

	@Override
	public void end() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void update(GameContainer gc, int delta) {
		// TODO Auto-generated method stub
		
	}

	/**
	 * Draws the screen.
	 */
	@Override
	public void draw(Graphics graphic) {
		LevelManager.drawCurrentLevel(graphic);
		Actor.drawAllActors();
		if(!fullyUpgraded){
			Storage.getTower().getUpgradeInfo().displayInfo(Config.TOWER_UPGRADE_INFO_POSITION, graphic);
		} else{
			graphic.drawString("This tower is fully upgraded.", Config.TOWER_UPGRADE_INFO_POSITION.x, Config.TOWER_UPGRADE_INFO_POSITION.y);
		}

		GameHud.drawHud(graphic);
	}

	/**
	 * Check all the new input presses.
	 */
	@Override
	public void inputPressed(GameInput input) {
		if(input == GameInput.ACTION && !fullyUpgraded){
			if(Storage.getTower().upgrade(Storage.getPlayer().getMoney()))
				quit();
		}else if(input == GameInput.BACK){
			quit();
		}
		
	}

	@Override
	public void inputDown(GameInput input) {
		// TODO Auto-generated method stub
		
	}
	private void quit() {
		Game.screenStack.pop();
	}
}
